package org.pz.controller;

import org.pz.dto.DatasourceDto;
import org.pz.entity.MallResult;
import org.pz.service.DataSourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;

@RestController
@RequestMapping("/datasource")
public class DatasourceController {

    @Autowired
    private DataSourceService dataSourceService;

    @RequestMapping("/add")
    public MallResult addDatasource(@RequestBody @Validated DatasourceDto dto){
        dataSourceService.addDataSource(dto);
        return MallResult.success();
    }

    @RequestMapping("/list")
    public MallResult listDatasource(){
        return MallResult.success(dataSourceService.list());
    }

    @PostConstruct
    public void init(){
        dataSourceService.initDatasource();
    }

}
